from django.db import models

#导入时间域
from django.utils import timezone

#基类
class Base(models.Model):

	#创建时间
	create_time = models.DateTimeField(default=timezone.now,null=True)

	class Meta:
		abstract = True


# 节点表
class Node(models.Model):

	id = models.AutoField(primary_key=True)
	name = models.CharField(max_length=100, unique=True)

	class Meta:
		db_table = "node"

	def __str__(self):
		return self.name


# 权限表
class Access(models.Model):

	id = models.AutoField(primary_key=True)
	name = models.CharField(max_length=100, unique=True)

	class Meta:
		db_table = "access"

	def __str__(self):
		return self.name


#用户类
class User(Base):

	id = models.AutoField(primary_key=True)
	username = models.CharField(max_length=100, unique=True)
	password = models.CharField(max_length=200)
	phone = models.CharField(max_length=64)
	email = models.EmailField(max_length=64)
	num = models.IntegerField(default=0)
	img = models.CharField(max_length=200)
	auth = models.ForeignKey(Access, on_delete=models.CASCADE)

	class Meta:
		db_table = "user"

	def __str__(self):
		return self.username


# 权限类
class Authorize(models.Model):

	id = models.AutoField(primary_key=True)
	auth_name = models.CharField(max_length=64)
	access = models.ManyToManyField(to="User",related_name="u_auth")

	class Meta:
		db_table = 'auth'

	def __str__(self):
		return self.auth_name


# 课程类
class Course(models.Model):

	id = models.AutoField(primary_key=True)
	course_name = models.CharField(max_length=64)
	price = models.DecimalField(max_digits=10,decimal_places=2)
	pid = models.IntegerField()
	user_id = models.IntegerField()
	video = models.CharField(max_length=64)

	class Meta:
		db_table = 'course'


# 课程关注
class Flow(Base):

	id = models.AutoField(primary_key=True)
	uid = models.IntegerField()
	course_id = models.IntegerField()

	class Meta:
		db_table = 'flow'



# 课程打分
class CCScore(Base):

	id = models.AutoField(primary_key=True)
	uid = models.IntegerField()
	cid = models.IntegerField()
	score = models.IntegerField()

	class Meta:
		db_table = 'score'



